home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch1 / Styles.frm (.txt) < prev    next >
Visual Basic Form  |  1999-06-15  |  21KB  |  612 lines

  1. VERSION 5.00
  2. Begin VB.Form frmStyles 
  3.    Caption         =   "Styles"
  4.    ClientHeight    =   4830
  5.    ClientLeft      =   825
  6.    ClientTop       =   1455
  7.    ClientWidth     =   8685
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   4830
  11.    ScaleWidth      =   8685
  12.    Begin VB.Frame Frame2 
  13.       Caption         =   "ForeColor"
  14.       Height          =   1575
  15.       Index           =   1
  16.       Left            =   0
  17.       TabIndex        =   31
  18.       Top             =   840
  19.       Width           =   2295
  20.       Begin VB.OptionButton optForeColor 
  21.          Caption         =   "Red"
  22.          BeginProperty Font 
  23.             Name            =   "MS Sans Serif"
  24.             Size            =   8.25
  25.             Charset         =   0
  26.             Weight          =   700
  27.             Underline       =   0   'False
  28.             Italic          =   0   'False
  29.             Strikethrough   =   0   'False
  30.          EndProperty
  31.          ForeColor       =   &H000000FF&
  32.          Height          =   255
  33.          Index           =   1
  34.          Left            =   120
  35.          TabIndex        =   36
  36.          Top             =   480
  37.          Width           =   1095
  38.       End
  39.       Begin VB.OptionButton optForeColor 
  40.          Caption         =   "Green"
  41.          BeginProperty Font 
  42.             Name            =   "MS Sans Serif"
  43.             Size            =   8.25
  44.             Charset         =   0
  45.             Weight          =   700
  46.             Underline       =   0   'False
  47.             Italic          =   0   'False
  48.             Strikethrough   =   0   'False
  49.          EndProperty
  50.          ForeColor       =   &H0000FF00&
  51.          Height          =   255
  52.          Index           =   2
  53.          Left            =   120
  54.          TabIndex        =   35
  55.          Top             =   720
  56.          Width           =   1095
  57.       End
  58.       Begin VB.OptionButton optForeColor 
  59.          Caption         =   "Blue"
  60.          BeginProperty Font 
  61.             Name            =   "MS Sans Serif"
  62.             Size            =   8.25
  63.             Charset         =   0
  64.             Weight          =   700
  65.             Underline       =   0   'False
  66.             Italic          =   0   'False
  67.             Strikethrough   =   0   'False
  68.          EndProperty
  69.          ForeColor       =   &H00FF0000&
  70.          Height          =   255
  71.          Index           =   3
  72.          Left            =   120
  73.          TabIndex        =   34
  74.          Top             =   960
  75.          Width           =   1095
  76.       End
  77.       Begin VB.OptionButton optForeColor 
  78.          Caption         =   "Black"
  79.          BeginProperty Font 
  80.             Name            =   "MS Sans Serif"
  81.             Size            =   8.25
  82.             Charset         =   0
  83.             Weight          =   700
  84.             Underline       =   0   'False
  85.             Italic          =   0   'False
  86.             Strikethrough   =   0   'False
  87.          EndProperty
  88.          ForeColor       =   &H00000000&
  89.          Height          =   255
  90.          Index           =   0
  91.          Left            =   120
  92.          TabIndex        =   33
  93.          Top             =   240
  94.          Width           =   1095
  95.       End
  96.       Begin VB.OptionButton optForeColor 
  97.          Caption         =   "White"
  98.          BeginProperty Font 
  99.             Name            =   "MS Sans Serif"
  100.             Size            =   8.25
  101.             Charset         =   0
  102.             Weight          =   700
  103.             Underline       =   0   'False
  104.             Italic          =   0   'False
  105.             Strikethrough   =   0   'False
  106.          EndProperty
  107.          ForeColor       =   &H00FFFFFF&
  108.          Height          =   255
  109.          Index           =   4
  110.          Left            =   120
  111.          TabIndex        =   32
  112.          Top             =   1200
  113.          Width           =   1095
  114.       End
  115.    End
  116.    Begin VB.Frame Frame2 
  117.       Caption         =   "FillColor"
  118.       Height          =   1575
  119.       Index           =   0
  120.       Left            =   2400
  121.       TabIndex        =   25
  122.       Top             =   840
  123.       Width           =   2295
  124.       Begin VB.OptionButton optFillColor 
  125.          Caption         =   "White"
  126.          BeginProperty Font 
  127.             Name            =   "MS Sans Serif"
  128.             Size            =   8.25
  129.             Charset         =   0
  130.             Weight          =   700
  131.             Underline       =   0   'False
  132.             Italic          =   0   'False
  133.             Strikethrough   =   0   'False
  134.          EndProperty
  135.          ForeColor       =   &H00FFFFFF&
  136.          Height          =   255
  137.          Index           =   4
  138.          Left            =   120
  139.          TabIndex        =   30
  140.          Top             =   1200
  141.          Width           =   1095
  142.       End
  143.       Begin VB.OptionButton optFillColor 
  144.          Caption         =   "Black"
  145.          BeginProperty Font 
  146.             Name            =   "MS Sans Serif"
  147.             Size            =   8.25
  148.             Charset         =   0
  149.             Weight          =   700
  150.             Underline       =   0   'False
  151.             Italic          =   0   'False
  152.             Strikethrough   =   0   'False
  153.          EndProperty
  154.          ForeColor       =   &H00000000&
  155.          Height          =   255
  156.          Index           =   0
  157.          Left            =   120
  158.          TabIndex        =   29
  159.          Top             =   240
  160.          Width           =   1095
  161.       End
  162.       Begin VB.OptionButton optFillColor 
  163.          Caption         =   "Blue"
  164.          BeginProperty Font 
  165.             Name            =   "MS Sans Serif"
  166.             Size            =   8.25
  167.             Charset         =   0
  168.             Weight          =   700
  169.             Underline       =   0   'False
  170.             Italic          =   0   'False
  171.             Strikethrough   =   0   'False
  172.          EndProperty
  173.          ForeColor       =   &H00FF0000&
  174.          Height          =   255
  175.          Index           =   3
  176.          Left            =   120
  177.          TabIndex        =   28
  178.          Top             =   960
  179.          Width           =   1095
  180.       End
  181.       Begin VB.OptionButton optFillColor 
  182.          Caption         =   "Green"
  183.          BeginProperty Font 
  184.             Name            =   "MS Sans Serif"
  185.             Size            =   8.25
  186.             Charset         =   0
  187.             Weight          =   700
  188.             Underline       =   0   'False
  189.             Italic          =   0   'False
  190.             Strikethrough   =   0   'False
  191.          EndProperty
  192.          ForeColor       =   &H0000FF00&
  193.          Height          =   255
  194.          Index           =   2
  195.          Left            =   120
  196.          TabIndex        =   27
  197.          Top             =   720
  198.          Width           =   1095
  199.       End
  200.       Begin VB.OptionButton optFillColor 
  201.          Caption         =   "Red"
  202.          BeginProperty Font 
  203.             Name            =   "MS Sans Serif"
  204.             Size            =   8.25
  205.             Charset         =   0
  206.             Weight          =   700
  207.             Underline       =   0   'False
  208.             Italic          =   0   'False
  209.             Strikethrough   =   0   'False
  210.          EndProperty
  211.          ForeColor       =   &H000000FF&
  212.          Height          =   255
  213.          Index           =   1
  214.          Left            =   120
  215.          TabIndex        =   26
  216.          Top             =   480
  217.          Width           =   1095
  218.       End
  219.    End
  220.    Begin VB.Frame Frame1 
  221.       Caption         =   "FillStyle"
  222.       Height          =   2295
  223.       Index           =   2
  224.       Left            =   2400
  225.       TabIndex        =   15
  226.       Top             =   2520
  227.       Width           =   2295
  228.       Begin VB.OptionButton optFillStyle 
  229.          Caption         =   "vbDiagonalCross"
  230.          Height          =   255
  231.          Index           =   7
  232.          Left            =   120
  233.          TabIndex        =   23
  234.          Top             =   1920
  235.          Width           =   1850
  236.       End
  237.       Begin VB.OptionButton optFillStyle 
  238.          Caption         =   "vbFSSolid"
  239.          Height          =   255
  240.          Index           =   0
  241.          Left            =   120
  242.          TabIndex        =   22
  243.          Top             =   240
  244.          Width           =   1850
  245.       End
  246.       Begin VB.OptionButton optFillStyle 
  247.          Caption         =   "vbFSTransparent"
  248.          Height          =   255
  249.          Index           =   1
  250.          Left            =   120
  251.          TabIndex        =   21
  252.          Top             =   480
  253.          Value           =   -1  'True
  254.          Width           =   1850
  255.       End
  256.       Begin VB.OptionButton optFillStyle 
  257.          Caption         =   "vbHorizontalLine"
  258.          Height          =   255
  259.          Index           =   2
  260.          Left            =   120
  261.          TabIndex        =   20
  262.          Top             =   720
  263.          Width           =   1850
  264.       End
  265.       Begin VB.OptionButton optFillStyle 
  266.          Caption         =   "vbVerticalLine"
  267.          Height          =   255
  268.          Index           =   3
  269.          Left            =   120
  270.          TabIndex        =   19
  271.          Top             =   960
  272.          Width           =   1850
  273.       End
  274.       Begin VB.OptionButton optFillStyle 
  275.          Caption         =   "vbUpwardDiagonal"
  276.          Height          =   255
  277.          Index           =   4
  278.          Left            =   120
  279.          TabIndex        =   18
  280.          Top             =   1200
  281.          Width           =   1850
  282.       End
  283.       Begin VB.OptionButton optFillStyle 
  284.          Caption         =   "vbCross"
  285.          Height          =   255
  286.          Index           =   6
  287.          Left            =   120
  288.          TabIndex        =   16
  289.          Top             =   1680
  290.          Width           =   1850
  291.       End
  292.       Begin VB.OptionButton optFillStyle 
  293.          Caption         =   "vbDownwardDiagonal"
  294.          Height          =   255
  295.          Index           =   5
  296.          Left            =   120
  297.          TabIndex        =   17
  298.          Top             =   1440
  299.          Width           =   1910
  300.       End
  301.    End
  302.    Begin VB.TextBox txtDrawWidth 
  303.       Height          =   285
  304.       Left            =   840
  305.       MaxLength       =   1
  306.       TabIndex        =   14
  307.       Text            =   "1"
  308.       Top             =   240
  309.       Width           =   375
  310.    End
  311.    Begin VB.Frame Frame1 
  312.       Caption         =   "DrawStyle"
  313.       Height          =   2295
  314.       Index           =   1
  315.       Left            =   0
  316.       TabIndex        =   2
  317.       Top             =   2520
  318.       Width           =   2295
  319.       Begin VB.OptionButton optDrawStyle 
  320.          Caption         =   "vbInsideSolid"
  321.          Height          =   255
  322.          Index           =   6
  323.          Left            =   120
  324.          TabIndex        =   13
  325.          Top             =   1680
  326.          Width           =   1455
  327.       End
  328.       Begin VB.OptionButton optDrawStyle 
  329.          Caption         =   "vbTransparent"
  330.          Height          =   255
  331.          Index           =   5
  332.          Left            =   120
  333.          TabIndex        =   12
  334.          Top             =   1440
  335.          Width           =   1455
  336.       End
  337.       Begin VB.OptionButton optDrawStyle 
  338.          Caption         =   "vbDashDotDot"
  339.          Height          =   255
  340.          Index           =   4
  341.          Left            =   120
  342.          TabIndex        =   11
  343.          Top             =   1200
  344.          Width           =   1455
  345.       End
  346.       Begin VB.OptionButton optDrawStyle 
  347.          Caption         =   "vbDashDot"
  348.          Height          =   255
  349.          Index           =   3
  350.          Left            =   120
  351.          TabIndex        =   10
  352.          Top             =   960
  353.          Width           =   1455
  354.       End
  355.       Begin VB.OptionButton optDrawStyle 
  356.          Caption         =   "vbDot"
  357.          Height          =   255
  358.          Index           =   2
  359.          Left            =   120
  360.          TabIndex        =   9
  361.          Top             =   720
  362.          Width           =   1455
  363.       End
  364.       Begin VB.OptionButton optDrawStyle 
  365.          Caption         =   "vbDash"
  366.          Height          =   255
  367.          Index           =   1
  368.          Left            =   120
  369.          TabIndex        =   8
  370.          Top             =   480
  371.          Width           =   1455
  372.       End
  373.       Begin VB.OptionButton optDrawStyle 
  374.          Caption         =   "vbSolid"
  375.          Height          =   255
  376.          Index           =   0
  377.          Left            =   120
  378.          TabIndex        =   7
  379.          Top             =   240
  380.          Value           =   -1  'True
  381.          Width           =   1455
  382.       End
  383.    End
  384.    Begin VB.Frame Frame1 
  385.       Caption         =   "Object"
  386.       Height          =   615
  387.       Index           =   0
  388.       Left            =   1320
  389.       TabIndex        =   1
  390.       Top             =   120
  391.       Width           =   3375
  392.       Begin VB.OptionButton ObjectChoice 
  393.          Caption         =   "Point"
  394.          Height          =   255
  395.          Index           =   3
  396.          Left            =   2520
  397.          TabIndex        =   24
  398.          Top             =   240
  399.          Width           =   735
  400.       End
  401.       Begin VB.OptionButton ObjectChoice 
  402.          Caption         =   "Box"
  403.          Height          =   255
  404.          Index           =   1
  405.          Left            =   960
  406.          TabIndex        =   6
  407.          Top             =   240
  408.          Width           =   615
  409.       End
  410.       Begin VB.OptionButton ObjectChoice 
  411.          Caption         =   "Line"
  412.          Height          =   255
  413.          Index           =   0
  414.          Left            =   120
  415.          TabIndex        =   5
  416.          Top             =   240
  417.          Value           =   -1  'True
  418.          Width           =   735
  419.       End
  420.       Begin VB.OptionButton ObjectChoice 
  421.          Caption         =   "Circle"
  422.          Height          =   255
  423.          Index           =   2
  424.          Left            =   1680
  425.          TabIndex        =   4
  426.          Top             =   240
  427.          Width           =   735
  428.       End
  429.    End
  430.    Begin VB.PictureBox picCanvas 
  431.       AutoRedraw      =   -1  'True
  432.       Height          =   4575
  433.       Left            =   4800
  434.       ScaleHeight     =   4515
  435.       ScaleWidth      =   3795
  436.       TabIndex        =   0
  437.       Top             =   240
  438.       Width           =   3855
  439.    End
  440.    Begin VB.Label Label1 
  441.       Caption         =   "DrawWidth"
  442.       Height          =   255
  443.       Left            =   0
  444.       TabIndex        =   3
  445.       Top             =   270
  446.       Width           =   855
  447.    End
  448. Attribute VB_Name = "frmStyles"
  449. Attribute VB_GlobalNameSpace = False
  450. Attribute VB_Creatable = False
  451. Attribute VB_PredeclaredId = True
  452. Attribute VB_Exposed = False
  453. Option Explicit
  454. Private Enum ObjectTypes
  455.     objLine = 0
  456.     objBox = 1
  457.     objCircle = 2
  458.     objPoint = 3
  459. End Enum
  460. Private ObjectType As ObjectTypes
  461. Private Rubberbanding As Boolean
  462. Private OldMode As Integer
  463. Private OldStyle As Integer
  464. Private FirstX As Single
  465. Private FirstY As Single
  466. Private LastX As Single
  467. Private LastY As Single
  468. ' Make the picCanvas as big as possible.
  469. Private Sub Form_Resize()
  470. Dim wid As Single
  471.     wid = ScaleWidth - picCanvas.Left
  472.     If wid < 120 Then wid = 120
  473.     picCanvas.Move picCanvas.Left, 0, wid, ScaleHeight
  474. End Sub
  475. ' Draw an ellipse bounded by a rectangle.
  476. Private Sub DrawEllipse(ByVal obj As Object, ByVal xmin As Single, ByVal ymin As Single, ByVal xmax As Single, ByVal ymax As Single)
  477. Dim cx As Single
  478. Dim cy As Single
  479. Dim wid As Single
  480. Dim hgt As Single
  481. Dim aspect As Single
  482. Dim radius As Single
  483.     ' Find the center.
  484.     cx = (xmin + xmax) / 2
  485.     cy = (ymin + ymax) / 2
  486.     ' Get the ellipse's size.
  487.     wid = xmax - xmin
  488.     hgt = ymax - ymin
  489.     ' Do nothing if the width or height is zero.
  490.     If (wid = 0) Or (hgt = 0) Then Exit Sub
  491.     aspect = hgt / wid
  492.     ' See which dimension is larger.
  493.     If wid > hgt Then
  494.         ' The major axis is horizontal.
  495.         ' Get the radius in custom coordinates.
  496.         radius = wid / 2
  497.     Else
  498.         ' The major axis is vertical.
  499.         ' Get the radius in custom coordinates.
  500.         radius = hgt / 2
  501.     End If
  502.     ' Draw the circle.
  503.     obj.Circle (cx, cy), radius, , , , aspect
  504. End Sub
  505. ' Draw the appropriate object.
  506. Private Sub DrawObject(ByVal xmin As Single, ByVal ymin As Single, ByVal xmax As Single, ByVal ymax As Single)
  507.     Select Case ObjectType
  508.         Case objLine
  509.             picCanvas.Line (xmin, ymin)-(xmax, ymax)
  510.         Case objBox
  511.             picCanvas.Line (xmin, ymin)-(xmax, ymax), , B
  512.         Case objCircle
  513.             DrawEllipse picCanvas, xmin, ymin, xmax, ymax
  514.         Case objPoint
  515.             picCanvas.PSet (xmax, ymax)
  516.     End Select
  517. End Sub
  518. ' Set the DrawStyle.
  519. Private Sub optDrawStyle_Click(Index As Integer)
  520.     picCanvas.DrawStyle = Index
  521. End Sub
  522. ' Set the FillColor.
  523. Private Sub optFillColor_Click(Index As Integer)
  524.     picCanvas.FillColor = optFillColor(Index).ForeColor
  525. End Sub
  526. ' Set the FillStyle.
  527. Private Sub optFillStyle_Click(Index As Integer)
  528.     picCanvas.FillStyle = Index
  529. End Sub
  530. ' Start a rubberbanding of some sort.
  531. Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  532.     ' Let MouseMove know we are rubberbanding.
  533.     Rubberbanding = True
  534.     ' Save values so we can restore them later.
  535.     OldMode = picCanvas.DrawMode
  536.     OldStyle = picCanvas.DrawStyle
  537.     picCanvas.DrawMode = vbInvert
  538.     If ObjectType = objLine Then
  539.         picCanvas.DrawStyle = vbSolid
  540.     Else
  541.         picCanvas.DrawStyle = vbDot
  542.     End If
  543.     ' Save the starting coordinates.
  544.     FirstX = X
  545.     FirstY = Y
  546.     ' Save the ending coordinates.
  547.     LastX = X
  548.     LastY = Y
  549.     ' Draw the appropriate rubberband object.
  550.     DrawObject FirstX, FirstY, LastX, LastY
  551. End Sub
  552. ' Continue rubberbanding.
  553. Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  554.     ' If we are not rubberbanding, do nothing.
  555.     If Not Rubberbanding Then Exit Sub
  556.     ' Erase the previous rubberband object.
  557.     DrawObject FirstX, FirstY, LastX, LastY
  558.     ' Save the new ending coordinates.
  559.     LastX = X
  560.     LastY = Y
  561.     ' Draw the new rubberband object.
  562.     DrawObject FirstX, FirstY, LastX, LastY
  563. End Sub
  564. ' Finish rubberbanding and draw the object.
  565. Private Sub picCanvas_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  566.     ' If we are not rubberbanding, do nothing.
  567.     If Not Rubberbanding Then Exit Sub
  568.     ' We are no longer rubberbanding.
  569.     Rubberbanding = False
  570.     ' Erase the previous rubberband object.
  571.     DrawObject FirstX, FirstY, LastX, LastY
  572.     ' Restore the original DrawMode and DrawStyle.
  573.     picCanvas.DrawMode = OldMode
  574.     picCanvas.DrawStyle = OldStyle
  575.     ' Draw the final object.
  576.     DrawObject FirstX, FirstY, LastX, LastY
  577. End Sub
  578. ' Select the default options.
  579. Private Sub Form_Load()
  580.     optForeColor(0).Value = True
  581.     optFillColor(0).Value = True
  582.     optDrawStyle(picCanvas.DrawStyle).Value = True
  583.     optFillStyle(picCanvas.FillStyle).Value = True
  584.     ObjectChoice(ObjectType).Value = True
  585.     txtDrawWidth.Text = Format$(picCanvas.DrawWidth)
  586. End Sub
  587. ' Record the kind of object to draw next.
  588. Private Sub ObjectChoice_Click(Index As Integer)
  589.     ObjectType = Index
  590. End Sub
  591. ' Set the ForeColor.
  592. Private Sub optForeColor_Click(Index As Integer)
  593.     picCanvas.ForeColor = optForeColor(Index).ForeColor
  594. End Sub
  595. ' Change set DrawWidth.
  596. Private Sub txtDrawWidth_Change()
  597. Dim wid As Integer
  598.     If Not IsNumeric(txtDrawWidth.Text) Then Exit Sub
  599.     wid = CInt(txtDrawWidth.Text)
  600.     If wid < 1 Then Exit Sub
  601.     picCanvas.DrawWidth = wid
  602. End Sub
  603. ' Only allow 1 through 9.
  604. Private Sub txtDrawWidth_KeyPress(KeyAscii As Integer)
  605.     If KeyAscii < Asc(" ") Or _
  606.        KeyAscii > Asc("~") Then Exit Sub
  607.     If KeyAscii >= Asc("1") And _
  608.        KeyAscii <= Asc("9") Then Exit Sub
  609.     Beep
  610.     KeyAscii = 0
  611. End Sub
  612.